package parking.manager;

import java.util.List;

public class Parking {
    
    private int _maxSlotsNumber;
    private int _slotsNumber;
    private List<Slot> _slots;
    
    public Parking(List<Slot> slots)
    {
        _maxSlotsNumber = slots.size();
        _slotsNumber = 0;
        _slots = slots;
    }

    public void ParkVehicle(String registrationNumber, String vehicleType, String bodyType)
    {
        _slotsNumber++;
        for (Slot slot : _slots) {
            if (slot.GetSlotStatus() == SlotStatus.Free) {
                if (vehicleType.equals("Car")) {
                    if (bodyType.equals("Normal")){
                        slot.ParkVehicle(new Car(registrationNumber, CarBodyType.Normal));
                    } else {
                        slot.ParkVehicle(new Car(registrationNumber, CarBodyType.Cabrio));
                    }
                } else if (vehicleType.equals("MotorBike")) {
                    slot.ParkVehicle(new MotorBike(registrationNumber));
                }
                break;
            }
        }
    }
    
    public void RemoveVehicle(int slotNumber)
    {
        for (Slot slot : _slots) {
            if (slot.GetOrderNumber() == slotNumber) {
                slot.ReleaseSlot();
            }
        }
    }
    
    public int GetFreeSlotsNumber()
    {
        return _maxSlotsNumber - _slotsNumber;
    }
    
    public List<Slot> GetSlots()
    {
        return _slots;
    }
}
